using System;
using System.Collections.Generic;
using System.Text;

namespace Toenda.Foundation.PluginBase {
	/// <summary>
	/// Implements a Component exceptiopn
	/// </summary>
	public class ComponentException : Exception {
		private string _message = "";
		private Exception _innerException;

		/// <summary>
		/// Creates a new instance of <see cref="ComponentException"/>
		/// </summary>
		public ComponentException() {
			this._message = "The component throw a exception.";
		}

		/// <summary>
		/// Creates a new instance of <see cref="ComponentException"/>
		/// </summary>
		/// <param name="message">Spezifies a own message</param>
		public ComponentException(string message) {
			this._message = message;
		}

		/// <summary>
		/// Creates a new instance of <see cref="ComponentException"/> and initializes it by the exception from the parameter
		/// </summary>
		/// <param name="exception"></param>
		public ComponentException(ComponentException exception) {
			this._message = exception.Message;
			this._innerException = exception.InnerException;
		}

		/// <summary>
		/// Creates a new instance of <see cref="ComponentException"/>
		/// </summary>
		/// <param name="message">Spezifies a own message</param>
		/// <param name="innerException">The innerException is a exception contained in this exception</param>
		public ComponentException(string message, Exception innerException) {
			this._message = message;
			this._innerException = innerException;
		}

		/// <summary>
		/// Gets he message
		/// </summary>
		public new string Message {
			get {
				StringBuilder str = new StringBuilder();

				str.Append("An exception from type [");
				str.Append(this.GetType().Name);
				str.Append("] was thrown.");

				if(this._message.Length > 0) {
					str.Append(" ");
				}

				str.Append(this._message);

				return str.ToString();
			}
		}

		/// <summary>
		/// Gets the inner exception
		/// </summary>
		public new Exception InnerException {
			get { return this._innerException; }
		}
	}
}
